/*************************************************************************
	> File Name: 3.solve.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2024-11-22 10:45:01
 ************************************************************************/

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

#define MAX_N 1000
int dp[MAX_N + 5][MAX_N + 5];
char s1[MAX_N + 5];
char s2[MAX_N + 5];

int main() {
    scanf("%s%s", s1 + 1, s2 + 1);
    int n = strlen(s1 + 1), m = strlen(s2 + 1);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            if (s1[i] == s2[j]) {
                dp[i][j] = max(dp[i - 1][j - 1] + 1, dp[i][j]);
            }
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}
